package com.clwl.supervise.superviseapp.config;


import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import com.clwl.supervise.superviseapp.entity.base.TsUser;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {


    @Bean("userRedisTemplate")
    public RedisTemplate<String, TsUser> getRedisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, TsUser> template = new RedisTemplate<>();
        //value值序列化
        template.setValueSerializer(new GenericFastJsonRedisSerializer());
        template.setHashValueSerializer(new GenericFastJsonRedisSerializer());
        //key值序列化
        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());
        //设置连接
        template.setConnectionFactory(factory);
        return template;
    }

}
